package cn.wolfcode.shop.cloud.mq;

import cn.wolfcode.shop.cloud.service.IOrderInfoService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

@RocketMQMessageListener(
        //consumerGroup组
        consumerGroup = MQConstants.ORDER_SUCCESS_GROUP,
        topic = MQConstants.SECKILL_ORDER,
        selectorType = SelectorType.TAG,
        selectorExpression = MQConstants.ORDER_SUCCESS_TAG
)
@Component
public class OrderSuccessMQListener implements RocketMQListener<Map> {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private IOrderInfoService orderInfoService;
    @Override
    public void onMessage(Map  map) {
        //判断订单的状态
        //如果没有，回补与库存，修改本地标识码
        //30分钟以后在查看状态，如果没有支付，在进行处理
        Message<Map> msg = (Message<Map>) MessageBuilder.withPayload(map).build();
        //级别3是10秒
        rocketMQTemplate.syncSend(MQConstants.ORDER_SUCCESS_DELAY_DEST, msg,3000,3);
    }
}